#
# 动态绑定属性和限制绑定
#
# 动态绑定属性
# 语法：对象.属性 = 初始值
class Car():
    def run(self):
        print("run")


car = Car()
car.run()
car.name = "宝马"
car.price = 100000


# print(car.name)
# print(car.price)


# 限定绑定:只能绑定某些属性
#
# 语法：slots = (属性1, 属性2,…………)
class Person(object):
    __slots__ = ('name', 'age')

    def eat(self, food):  # 实例方法有一个参数self,指的是实例对象
        print(food)


p1 = Person()
p1.name = 'Lucy'
print(p1.name)
p1.age = 18
print(p1.age)
# p1.height = 178  # AttributeError: 'Person' object has no attribute 'height'


class Person(object):
    num = 10


p11 = Person()
p12 = Person()
# p11.num 和 p12.num访问的是同一个num，num来自于类属性，当前类持有，通过该类创建的所有的对象都持有
print(p11.num is p12.num)  # True
print(p11.num, p12.num)  # 10 10
